﻿package com.PlantVsZombies.Zombies;

import java.util.List;

import com.PlantVsZombies.common.Life;
import com.PlantVsZombies.constant.Constant;
import com.PlantVsZombies.constant.GameVariable;
import com.PlantVsZombies.pass.PassBuilder;
import com.PlantVsZombies.pass.PassGroup;
import com.PlantVsZombies.pass.PassMeta;
import com.PlantVsZombies.ui.GamePanel;
import com.PlantVsZombies.ui.PlantsMap;

public class Pass extends Life implements Constant {
	// public static int chosedPass = 1;//选择关卡
	public static boolean lastSnag; // 最后一波
	public static boolean passOver;// 此关是否结束
	public static int zombieNum;
	private PassMeta passMeta;

	public Pass(int chosedPass) {

		System.out.println("第" + chosedPass + "关");

		passMeta = GameVariable.list.get(chosedPass - 1);
		zombieNum = PassBuilder.getZombieNumber(passMeta);
		PlantsMap.zombies.removeAll(PlantsMap.zombies);

	}

	@Override
	public int doRun() {
		System.out.println("启动");

		if (!isLive()) {
			return 0;
		}
		for (PassGroup group : passMeta.getGroups()) {
			for (int zombie : group.getZombies()) {
				try {
					Thread.sleep(Constant.PRODUCE_ZOMBIE_SPEED);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				PlantsMap.zombies.add(RandomZombie.randomZombie(zombie));
				zombieNum--;
			}

			try {
				Thread.sleep(Constant.GROUP_ZOMBIE_SPEED);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}

			if (GamePanel.isPass || GamePanel.isGameOver) {
				return 0;
			}
		}
		passOver = true;
		return 0;
	}

}
